package org.scohen.juploadr.uploadapi.zooomr;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.scohen.juploadr.prefs.Configuration;

public class Messages {
    private static final String BUNDLE_NAME = "org.scohen.juploadr.uploadapi.zooomr.messages"; //$NON-NLS-1$

    private static final Configuration config = Configuration.getInstance();
    private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(
            BUNDLE_NAME, config.getLocale());

    private Messages() {
    }

    public static String getString(String key) {

        if (!RESOURCE_BUNDLE.getLocale().equals(config.getLocale())) {
            RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, config
                    .getLocale());
        }

        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
    
    public static String getString(String key, Object... args){
        return MessageFormat.format(getString(key),args);
     }
}
